package sg.edu.nus.iss.vmcs.controller;

import sg.edu.nus.iss.vmcs.util.VMCSException;

/**
 * 
 * @author Chomeaye
 *
 */

public class FaultDetected implements CoinReceiverState {

	private static FaultDetected instance=null;
	
	
	private FaultDetected(){}
	
	
	public static FaultDetected GetInstance() {
		if (instance== null)
		{instance=new FaultDetected();
		}
		return instance;
	}
	
	@Override
	public void continueReceive(CoinReceiver coinReceiver) throws VMCSException {
		
		throw new VMCSException("CoinReceiverFaultDetected.ContinueReceive", "Coin Receiver is in coin receiving state.");

	}

	@Override
	public void receiveCoin(CoinReceiver coinReceiver, double totAmtInserted)
			throws VMCSException {
		
		throw new VMCSException("FaultDetected.ContinueReceive", "Coin Receiver is in coin receiving state.");
	}

	@Override
	public void refundCash(CoinReceiver coinReceiver) throws Exception {
		
		double totalInsertedMoney=coinReceiver.getTotalInserted();
		
		if (totalInsertedMoney >0) 
		{
			coinReceiver.getTransactionController().displayReutndMoney(totalInsertedMoney);
			
		}
			
		coinReceiver.setState(CoinReceiverIdle.GetInstance());
	
		
	}

	@Override
	public void startCoinReceiver(CoinReceiver coinReceiver)
			throws VMCSException {
		
		throw new VMCSException("FaultDetected.StartCoinReceiver", "Coin Receiver in Fault Detected State.");
		
	}

	@Override
	public void startReceive(CoinReceiver coinReceiver) throws VMCSException {
	
		throw new VMCSException("FaultDetected.StartReceive", "Coin Receiver in Fault Detected State.");
		
	}

	@Override
	public void stopCoinReceiver(CoinReceiver coinReceiver)
			throws VMCSException {
		
		coinReceiver.getTransactionController().allowCoinInputBoxSelection(false);
		coinReceiver.getTransactionController().allowDrinkSelectionBox(true);
		
		
	}

	@Override
	public void stopReceive(CoinReceiver coinReceiver) throws VMCSException {
	
		throw new VMCSException("FaultDetected.StopReceive", "Coin Receiver in Fault Detected State.");
		
	}

	@Override
	public boolean storeCash(CoinReceiver coinReceiver) throws VMCSException {
		
		throw new VMCSException("FaultDetected.StoreCash", "Coin Receiver in Fault Detected State.");

	}

	@Override
	public void terminateFault(CoinReceiver coinReceiver) throws Exception {
	
		throw new VMCSException("FaultDetected.TerminateFault", "Coin Receiver in Fault Detected State.");
		
	}

}
